package com.linq.cool.system.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.linq.cool.api.domain.SysDept;
import com.linq.cool.system.domain.SysMenu;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: yqlin
 * @Date: 2021/1/22 23:05
 * @Description: TreeSelect树结构实体类
 * @Version: 1.0.0
 */
@NoArgsConstructor
@Data
@Accessors(chain = true)
public class TreeSelectVO implements Serializable {
    private static final long serialVersionUID = 5291486923642015033L;
    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;
    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelectVO> children;

    public TreeSelectVO(SysDept dept) {
        this.id = dept.getId();
        this.label = dept.getName();
        this.children = dept.getChildren().stream().map(TreeSelectVO::new).collect(Collectors.toList());
    }

    public TreeSelectVO(SysMenu menu) {
        this.id = menu.getId();
        this.label = menu.getName();
        this.children = menu.getChildren().stream().map(TreeSelectVO::new).collect(Collectors.toList());
    }
}
